package com.dk.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dk.pojo.Menu;
import com.dk.pojo.TPerson;
import com.dk.service.menuservice;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("menu")
public class menucontroller {
    @Reference
    private menuservice menuservice;

    @RequestMapping("toshow")
    public String toshow() {
        return "show";
    }
    @RequestMapping("getinfo")
    @ResponseBody
    public List<Map<String,Object>> getinfo(HttpServletRequest request){
        TPerson user = (TPerson) request.getSession().getAttribute("userLogin");
        System.out.println(user.getPid());
        List<Map<String,Object>> list = menuservice.selectgetinfo(user.getPid());
        return list;
    }

    @RequestMapping("toZtree")
    public String toZtree(){
        return "menu/show";
    }
    @RequestMapping("getInfoZtree")
    @ResponseBody
    public List<Map<String,Object>> getInfoZtree(){
        List<Map<String,Object>> list = menuservice.selectZtree();
        return list;
    }

    //zj
    @RequestMapping("toAdd")//跳转增加页面
    public String toAdd(){
        return "menu/insert";
    }

    @RequestMapping("add")
    @ResponseBody
    public boolean add(Menu menu){//增加
        return menuservice.add(menu);
    }

    @RequestMapping("toUpdate/{parentid}")
    public String toUpdate(@PathVariable("parentid")Integer parentid, Model model){//回显
        Menu menu = menuservice.toUpdate(parentid);
        model.addAttribute("menu",menu);
        return "menu/update";
    }

    @RequestMapping("updateInfo")//修改
    @ResponseBody
    public boolean updateInfo(Menu menu){//修改
        return menuservice.updateInfo(menu);
    }

    @RequestMapping("deleteInfo/{parentid}")//删除
    @ResponseBody
    public boolean deleteInfo(@PathVariable("parentid")Integer parentid){//删除
        return menuservice.deleteInfo(parentid);
    }



    //checked
    @RequestMapping("getInfoZtreeChecked/{roleId}")
    @ResponseBody
    public List<Map<String,Object>> getInfoZtreeChecked(@PathVariable("roleId")Integer roleId){
        List<Map<String,Object>> list = menuservice.selectgetZtreeChecked(roleId);
        return list;
    }
}
